package com.allwees.bs.configuration;

import com.allwees.bs.module.sys.dao.SysFileInfoDao;
import com.allwees.bs.module.sys.entity.SysFileInfo;
import com.allwees.core.common.util.reflect.PojoUtil;
import com.allwees.support.fileservice.config.FileConfig;
import com.allwees.support.fileservice.fileinfo.dao.FileInfoDao;
import com.allwees.support.fileservice.fileinfo.entity.FileInfo;
import com.allwees.support.fileservice.upload.UploadFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class UploadConfiguration {

    @Autowired
    private FileConfig config;

    @Bean
    public UploadFileUtil uploadFileUtil(SysFileInfoDao sysFileInfoDao)    {
        UploadFileUtil uploadFileUtil = new UploadFileUtil();

        uploadFileUtil.init(config, new FileInfoDao() {
            @Override
            public void save(FileInfo fileInfo) {
                sysFileInfoDao.insert(PojoUtil.copy(new SysFileInfo(), fileInfo));
            }
        });
        return uploadFileUtil;
    }
}
